{% extends "base.html" %}
{% block title %}{% endblock %}
{% block content %}
<br>
<div class="layui-body" style="overflow:auto;left:1px">
    <br>
    <ul class="layui-timeline" id="timeList">

    </ul>

    <div class="demoTable">
        <br>
        <form class="layui-form" action="" id="workTable">
            <div class="layui-input-inline">
                <label class="layui-form-label">进度：</label>
                <div class="layui-input-inline">
                    <input type="text" class="layui-input" lay-verify="required|mynum" name="process" id="process"
                           placeholder="请输入" style="width:212px">
                </div>
            </div>
            <div class="layui-input-inline">
                <label class="layui-form-label">备注：</label>
                <div class="layui-input-inline">
                    <input type="text" class="layui-input" name="note" id="note" placeholder="请输入" style="width:212px">
                </div>
            </div>
            <div class="layui-input-inline">
                <div class="layui-input-inline">
                    <button class="layui-btn layui-btn-normal" id="save" lay-submit lay-filter="formDemo">保存</button>
                </div>
            </div>
            <br><br>
        </form>

    </div>
</div>
<script>
    function getRemark(){
        CacheProcess = layui.data('test').processList;
        $.ajax({
                                    //发出请求
                                    type:"GET",
                                    url:"/casePlan/main/process/srh",
                                    contentType: 'application/json; charset=utf-8',
                                    dataType:"json",
                                    data:{"id":CacheProcess.id,"t":CacheProcess.t},
                                    success: function(result){
                                        strHtml = "";
                                        result.data.forEach(function(value, index, array) {

                                            timeStr = '<li class="layui-timeline-item">'+
                                                       ' <i class="layui-icon layui-timeline-axis">&#xe63f;</i>'+
                                                       '   <div class="layui-timeline-content layui-text">'+
                                                       '    <h3 class="layui-timeline-title">'+value.update_time+''+
                                                       '&nbsp;&nbsp;<span style="color:green">进度：</span><span style="color:red">'+value.process+
                                                       '%</span>        &nbsp;&nbsp;<span style="color:green">'+value.note+'</span></h3>'+
                                                       '    </div>'+
                                                       ' </li>';
                                            strHtml = strHtml + timeStr;
                                        });
                                        newHtml = '<ul class="layui-timeline" id="timeList">'+strHtml+'</ul>';
                                        $('#timeList').html(newHtml);
                                    }
        });
    }
    layui.use(['table','code'], function(){
          var table = layui.table
          ,form = layui.form;
          var $= layui.jquery;
          //
          userId = userId = layui.data('test').UserInfo.userId;
          getRemark();

          form.verify({
                mynum: [
                    /^0$|^[1-9]+\d*$/,
                    '请填写数字(自然数)'
                ],
            });
          //监听提交
          form.on('submit(formDemo)', function(data){
            process = data.field.process;
            if(process>100){layer.msg("进度请不要超过100");return false;}
            if(process==""){layer.msg("进度不能为空!");return false;}
            if(CacheProcess.t==0){
                data = {"case_plan_id":CacheProcess.id,"case_sub_plan_id":0,"process":process,"note":data.field.note,"up_person":userId}
            }else{
                data = {"case_plan_id":0,"case_sub_plan_id":CacheProcess.id,"process":process,"note":data.field.note,"up_person":userId}
            }
            $.ajax({
                        //发出请求
                        type:"POST",
                        url:"/casePlan/main/process/manage",
                        contentType: 'application/json; charset=utf-8',
                        dataType:"json",
                        data:JSON.stringify(data),
                        success: function(result){
                            layer.msg("添加成功!");
                            getRemark();
                            $('#note').val("");
                        }
            });

            return false;
          });
          form.render();

    });

</script>
{% endblock %}